#ifndef __NetworkManager_H__
#define __NetworkManager_H__

#include <vector>
#include <map>
#include <string>

#include "curl/curl.h"
#include "cocoa/CCObject.h"

USING_NS_CC;

class JsonObject;

class Msg
{
public:

	enum
	{
		Error = 0,

		GameRequestCreated = 10,
		GameUpdate = 11
	};

};

class NetworkManager : public CCObject
{
public:

	static NetworkManager* getInstance();

	void call( const char * method, CCObject* target, SEL_CallFuncO onSuccess, SEL_CallFuncO onFailed,
		const std::map<std::string,std::string>* bParams = NULL, bool bPost = false);

	CCObject* getCallbackTarget();

	SEL_CallFuncO getCallbackSuc();

	SEL_CallFuncO getCallbackFail();

private:
	NetworkManager();

	virtual ~NetworkManager();

	static size_t process_data( void *buffer, size_t size, size_t nmemb, void *user_p );

	static size_t process_binary_data( void* buffer, size_t size, size_t nmemb, void*user_p);

	int curl_debug_callback (CURL *, curl_infotype, char *, size_t, void *);

	static NetworkManager* sInstance;

	bool cheakError( JsonObject* serverData );


	CURL*					m_connection;
	std::string				m_stringBuffer;
	unsigned char*			m_binaryBuffer;
	int						m_binarySize;

	CCObject*		m_pTarget;
	SEL_CallFuncO			m_sucfunc;
	SEL_CallFuncO			m_failfunc;
	void					clearCallback();

	std::string				m_baseURL;

	bool					init();
};

#endif // __NetworkManager_H__